from django.db import models
from apps.users.models import User

class Activity(models.Model):
    """活动模型"""
    title = models.CharField(max_length=200, verbose_name='活动标题')
    description = models.TextField(verbose_name='活动描述')
    time = models.DateTimeField(verbose_name='活动时间')
    location = models.CharField(max_length=200, verbose_name='活动地点')
    status = models.CharField(max_length=20, default='进行中', verbose_name='活动状态')
    creator = models.ForeignKey(User, on_delete=models.CASCADE, related_name='created_activities', verbose_name='创建者')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        db_table = 'activity'
        verbose_name = '活动'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']

class ActivityParticipant(models.Model):
    """活动参与者模型"""
    activity = models.ForeignKey(Activity, on_delete=models.CASCADE, related_name='participants', verbose_name='活动')
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='participated_activities', verbose_name='参与者')
    joined_at = models.DateTimeField(auto_now_add=True, verbose_name='参加时间')

    class Meta:
        db_table = 'activity_participant'
        verbose_name = '活动参与者'
        verbose_name_plural = verbose_name
        unique_together = ('activity', 'user')

class ActivityTag(models.Model):
    """活动标签模型"""
    activity = models.ForeignKey(Activity, on_delete=models.CASCADE, related_name='tags', verbose_name='活动')
    name = models.CharField(max_length=50, verbose_name='标签名')

    class Meta:
        db_table = 'activity_tag'
        verbose_name = '活动标签'
        verbose_name_plural = verbose_name 